package com.solocredit.finance.ui.market.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.solocredit.finance.R
import com.solocredit.finance.base.adapter.MullaRecyclerViewAdapter
import com.solocredit.finance.base.adapter.MullaViewHolderHelper
import org.json.JSONObject

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/8/5 14:42
 * @Annotation：贷款申请 明细 适配器
 */
class MullaApplyDetailsAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_apply_details_title) {
    override fun setItemChildListener(helper: MullaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    @SuppressLint("SetTextI18n")
    override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
        val textTitle = helper.getTextView(R.id.textTitle)
        textTitle.text = model.optString("showName")

        val textValue = helper.getTextView(R.id.textValue)
        textValue.text = model.optString("showDetail")

        val childArray = model.optJSONArray("childList")
        val childList = arrayListOf<JSONObject>()
        if (childArray != null) {
            for (i in 0..<childArray.length()){
                childList.add(childArray.optJSONObject(i))
            }
        }

        val recyclerView = helper.getView<RecyclerView>(R.id.recyclerView)
        recyclerView.setHasFixedSize(true)
        recyclerView.isNestedScrollingEnabled = false
        recyclerView.isFocusableInTouchMode = false //不需要焦点
        recyclerView.layoutManager = LinearLayoutManager(mContext)
        val adapter = MullaApplyDescAdapter(recyclerView)
        recyclerView.adapter = adapter
        recyclerView.itemAnimator = DefaultItemAnimator()
        adapter.data = childList
    }

    class MullaApplyDescAdapter(recyclerView: RecyclerView?) : MullaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_mulla_apply_details_desc) {
        @SuppressLint("SetTextI18n")
        override fun fillData(helper: MullaViewHolderHelper, position: Int, model: JSONObject) {
            val textTitle = helper.getTextView(R.id.textTitle)
            textTitle.text = model.optString("showName")

            val textDesc = helper.getTextView(R.id.textDesc)
            textDesc.text = model.optString("showDetail")
        }
    }
}